package com.zhkj.txg.module.mine.ui

import android.Manifest
import android.app.Activity
import android.content.Intent
import android.net.Uri
import android.text.Editable
import android.text.TextWatcher
import android.view.View
import androidx.appcompat.app.AlertDialog
import androidx.lifecycle.Observer
import androidx.recyclerview.widget.LinearLayoutManager
import com.zhkj.lib.base.ViewModelActivity
import com.zhkj.lib.http.HttpResponseStatus
import com.zhkj.txg.R
import com.zhkj.txg.module.mine.adapter.ProblemAdapter
import com.zhkj.txg.module.mine.vm.FeedbackViewModel
import com.zhkj.txg.module.mine.vm.ProblemViewModel
import kotlinx.android.synthetic.main.activity_problem.*


class ProblemActivity : ViewModelActivity<ProblemViewModel>() {
    override fun setViewModel(): ProblemViewModel = createViewModel()
    override fun statusTitleBar(): View? = titleProblem
    override val layoutResId: Int = R.layout.activity_problem


    companion object {
        fun open(activity: Activity) {
            val intent = Intent(activity, ProblemActivity::class.java)
            activity.startActivity(intent)
        }
    }

    private val problemAdapter: ProblemAdapter = ProblemAdapter()

    override fun initUI() {

        with(recyclerProblemContent) {
            layoutManager = LinearLayoutManager(this@ProblemActivity)
            adapter = problemAdapter
        }
    }

    override fun initData() {
        viewModel.getCommonProblem()
    }

    override fun initViewModel() {

        viewModel.problemLiveData.observe(this, Observer { response ->
            if (response.status == HttpResponseStatus.Status.SUCCESS) {
                response?.response?.let {
                    problemAdapter.setNewData(it.data)
                }
            }
        })


        viewModel.problemDetailLiveData.observe(this, Observer { response ->
            if (response.status == HttpResponseStatus.Status.SUCCESS) {
                response?.response?.let {

                }
            }
        })
    }
}